﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tworzenie_Grafiku
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private List<Pracownik> pracownik;
        public MainWindow()
        {
            InitializeComponent();
     
            
        }
        private void Zaloguj(object sender, RoutedEventArgs e)
        {
            blad_przy_logowaniu.Visibility = System.Windows.Visibility.Collapsed;
            Autoryzacja(identyfikator.Text, haslo.Password);
        }
        protected void Autoryzacja(String login, String password)
        {

            
            using (LINQtoDBDataContext db = new LINQtoDBDataContext())
            {
                var records = from record in db.Pracowniks where record.Nazwisko==login && record.Haslo==password

                              select record;
                pracownik = records.ToList();
            }
            if (pracownik.Count() > 0)
            {
                foreach (Pracownik wiersz in pracownik)
                {

                    new Menu(wiersz.Id_pracownika.ToString(), wiersz.Imie, wiersz.Nazwisko,wiersz.Stanowisko); 
                    this.Close();
                }
            }
        
               else
            blad_przy_logowaniu.Visibility = System.Windows.Visibility.Visible;
            
            
        }
    }
}
